﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using NovoSerDesEva;
using Sunny.UI;

namespace NovoSerDes
{
    public partial class BandwidthCameraPanel : UIPanel
    {
        BandwidthCamera parent;
        int curPanelIndex = 0;
        int whichPipe;

        public BandwidthCameraPanel(BandwidthCamera _parent,int _typePanelIndex)
        {
            InitializeComponent();
            this.RectSides = ToolStripStatusLabelBorderSides.None;
            parent = _parent;
            curPanelIndex = _typePanelIndex;
            this.uiComboBox_Type.SelectedItem = "RAW8 DBL";
            this.uiComboBox_Pipe.SelectedItem = "X";
            DpiSet();
        }

        public int WhichType
        {
            get { return whichPipe; }
        }

        private void uiButton_RemoveType_Click(object sender, EventArgs e)
        {
            List<BandwidthCameraPanel> TypePanels = parent.GetTypePanels();
            if (TypePanels.Count > 0)
            {
                BandwidthCameraPanel curTypePanel = this;
                parent.GetPanel2().Controls.Remove(curTypePanel);
                TypePanels.Remove(curTypePanel);
                parent.TypePanelIndex--;
                parent.ThisParent.CalculatorAll();
            }
            //System.Console.WriteLine(parent.TypePanelIndex);
            //刷新排版
        }

        private float GetDPI()
        {
            using (Graphics graphics = Graphics.FromHwnd(IntPtr.Zero))
            {
                float dpiX = graphics.DpiX;
                float dpiY = graphics.DpiY;
                return dpiX;
            }
        }

        private void DpiSet()
        {
            double dpi = GetDPI();
            double scale = dpi / 0.96;
            if (scale == 150 || scale == 125) //100% - 96 DPI;125% - 120 DPI;150% - 144 DPI;175% - 168 DPI;200% - 192 DPI
            {
                foreach (Control control in this.Controls)
                {
                    // 检查控件是否有Font属性，并且是否支持更改  
                    if (control.Font != null)
                    {
                        control.Font = new System.Drawing.Font("宋体", 9F);
                    }
                }
            }
        }

        private void uiComboBox_Pipe_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (uiComboBox_Pipe.SelectedIndex)
            {
                case 0:
                    whichPipe = 0;
                    break;
                case 1:
                    whichPipe = 1;
                    break;
                case 2:
                    whichPipe = 2;
                    break;
                case 3:
                    whichPipe = 3;
                    break;
            }
            parent.ThisParent.CalculatorAll();
        }
    }
}
